package site.nullable.recorder.data.model

import android.content.ContentValues
import java.io.File
import java.util.Date

data class Recording(
    val id: Long = 0,
    val fileName: String,
    val filePath: String,
    val duration: Long = 0,
    val dateCreated: Date = Date(),
    val fileSize: Long = 0,
) {
    val displayName: String
        get() = fileName.removeSuffix(".m4a")

    val formattedDate: String
        get() = android.text.format.DateFormat.format("yyyy-MM-dd HH:mm", dateCreated).toString()

    val formattedDuration: String
        get() {
            val seconds = duration / 1000
            val minutes = seconds / 60
            val remainingSeconds = seconds % 60
            return String.format("%02d:%02d", minutes, remainingSeconds)
        }

    val formattedSize: String
        get() {
            return when {
                fileSize >= 1024 * 1024 -> String.format("%.1f MB", fileSize / (1024.0 * 1024.0))
                fileSize >= 1024 -> String.format("%.1f KB", fileSize / 1024.0)
                else -> String.format("%d B", fileSize)
            }
        }

    fun fileExists(): Boolean {
        return File(filePath).exists()
    }
}